import {Component, OnInit} from '@angular/core';
import {HttpService} from '../../service/http.service';
import {ApiPath} from '../../config/api-path';
import {AlertController} from '@ionic/angular';
import {Router} from '@angular/router';
import {Location} from '@angular/common';

@Component({
  selector: 'app-advice-form',
  templateUrl: './advice-form.component.html',
  styleUrls: ['./advice-form.component.scss'],
})
export class AdviceFormComponent implements OnInit {
  files = [];
  multiple = false;
  multipleTab = 0;
  constructor(
    private HttpSrv: HttpService,
    private router: Router,
    private location:  Location,
    private alertCtrl: AlertController
  ) {
  }

  ngOnInit() {
    this.initi();
  }

  advice: string;

  /**
   * 发送按钮绑定该函数。
   */
  sendAdvice() {
    this.HttpSrv.httpPost<any>(ApiPath.request.advice.sendAdvice, {
      advice: this.advice,
    }).subscribe(res => {
      if (res.code == 0) {
        this.showAlert('发送成功！').then(r => r);
      }else
        {this.showAlert(res.msg).then(r => r);}
    });
    this.router.navigate(['ynuer/help']).then(r => r);
  }

  initi() {

  }

  async showAlert(msg: string) {
    const alert = await this.alertCtrl.create({
      message: msg,
      buttons: ['确定']
    });
    await alert.present();
  }
  fileChange(event) {}
  imageClick(event) {}
  onLeftClick() {
    this.location.back();
  }
}
